<?php

/**
 * Description of Category
 *
 * @author Vu
 */
 
class Category extends Zend_Db_Table_Abstract {
	
	protected $_name = 'cms_category';
    protected $_primary = 'category_id';
    
	public function getAllCategories($page = 1, $order = "name"){
        $tb = Zend_Db_Table::getDefaultAdapter();
        $tb->setFetchMode(Zend_Db::FETCH_OBJ);
        
        $select = $tb->select()->from('cms_category')->order($order);
        
        $paginator = Zend_Paginator::factory($select);
    	$paginator->setItemCountPerPage(Zend_Registry::get('page_size'));
    	$paginator->setCurrentPageNumber($page);
           
        return $paginator;
    }
    
	public function getAll(){
        $tb = Zend_Db_Table::getDefaultAdapter();
        $tb->setFetchMode(Zend_Db::FETCH_OBJ);
        
        $select = $tb->select()->from('cms_category')->order('name');
        
    	$rows = $tb->fetchAll($select);
           
        return $rows;
    }
    
	public function getCategoryById($categoryid){
        $row = $this->fetchRow($this->select()->where('category_id=?',$categoryid));
        
        return $row;
    }
}